# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=half
pkgname=haskell-half
pkgver=0.3.1
pkgrel=129
pkgdesc="Half-precision floating-point"
url="https://github.com/ekmett/half"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs')
makedepends=('ghc' 'uusi' 'haskell-quickcheck' 'haskell-test-framework'
             'haskell-test-framework-quickcheck2')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('39d2a20590f5d7f6c31ed9667a18dab9da88f145c3de910a2212c6dc4925ffbcfa7695548516b1ddeb1a44979ba0daba15615451e05437e0a6491a95f152f440')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    # https://github.com/ekmett/half/issues/35
    runhaskell Setup test --show-details=direct || echo "Tests failed"
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
